<template>
	<view class="buy">
		<view class="title">
			<image src="../../static/image/travel/matching/buy.png"></image>
			<text class="text">余额：</text>
			<text class="num">{{my_money}}</text>
			<view class="detail-btn" @click="goDetail">余额明细</view>
		</view>
<!-- 		<view class="number">
			<view class="list">
				<view :class="num == index ? 'item real' : 'item'" v-for="(item, index) in list" :key="index"
					@click="pick(index,item.money)">
					<view class="card">
						<text class="money">{{ item.money }}元</text>
					</view>
					<view v-if="index === 3" class="recommend">
						<text>推荐</text>
					</view>
				</view>
			</view>
			<view class="sure" @tap="recharge()">
				<text>确定充值</text>
			</view>
		</view> -->
<!-- 		<view class="tip">
			<text class="titl">温馨提示</text>
			<view>
				<text>1、充值即代表已阅读并同意</text>
				<text>《P币充值服务条款》；</text>
			</view>
			<view>
				<text>2、请在网络状态良好的情况下进行充值，为了保证充值顺利，请耐心等待充值，不要进行其他操作；</text>
			</view>
			<!-- <view>
				<text>3、前往账单记录，可查询充值订单详情和消费详情；</text>
			</view> -->
			<!-- <view>
				<text>3、在付款成功后，余额到账有些许延迟，超过一分钟未到账请联系客服；</text>
			</view>
			<view>
				<text>4、在支付过程中遇到任何问题，请联系官方客服：</text>
				<text>小助手</text>
			</view>
		</view> --> 
	</view>
</template>

<script>
	import Config from "@/common/config.js"; // 本地配置数据
	export default {
		data() {
			return {
				my_money:0,
				money: 0.01,
				num: 0,
				list: [{
						number: '4',
						money: '10',
					},
					{
						number: '13',
						money: '50',
					},
					{
						number: '21',
						money: '100',
					},{
						number: '21',
						money: '500',
					},{
						number: '21',
						money: '1000',
					},
				],
			};
		},
		created() {
			
		},
		onShow(){
			let userinfo = uni.getStorageSync('userinfo');
			// console.log(userinfo)
			
			let data = {
				im_tourists_token:userinfo.auth_token
			}
			
			this.$u.post('/api/Redpacket/userinfo',
				data).then(res => {
					
					this.my_money  = res.data.money
				});
		},
		methods: {
			goDetail() {
			  uni.navigateTo({
			    url: '/pages/signin/moneylog' // 修改为你的“余额明细”页面实际路径
			  });
			},
			pick(index, money) {
				this.num = index;
				this.money = money
			},
			recharge() {
				// alert(this.money)
				let userinfo = uni.getStorageSync('userinfo');
				
				//杉德接口
				let data = {
					type: 'wechat',
					method: 'wap',
					code: null,
					money: this.money,
					im_tourists_token:userinfo.auth_token
				}
				
				

				this.$u.post('/api/Redpacket/recharge',
					data).then(res => {
					console.log("充值响应", res);
					console.log("this.money", this.money);
					// return;
					let orderid = res.data.orderid;

					let orderjson = {
						"version": "10",
						"mer_no": "663611000015447",
						// "mer_key": "",
						"mer_order_no": res.data.orderid,
						"create_time": Date.now(),
						"expire_time": Date.now() + 1000 * 60 * 5,
						"order_amt": this.money,
						"notify_url": `https://${Config.baseUrl}/api/Redpacket/url_notify`,
						"return_url": `https://${Config.baseUrl}/api/Redpacket/url_notify`,
						"create_ip": "",
						"goods_name": "购买商品",
						"store_id": "100001",
						"product_code": "01000001",
						"clear_cycle": "0",
						"pay_extra": "{\"wx_app_id\":\"wx4d578fb71009cfb5\",\"gh_ori_id\":\"gh_e1f92199a6e8\",\"path_url\":\"pages/zf/index?\",\"miniProgramType\":\"0\"}",
						// "jump_scheme": "sandcash://",
						"jump_scheme": "hemacash://hmpay", //支付宝跳转
						"sign_type": "RSA",
						"accsplit_info": "N",
						"sign": "",
						"meta_option": "[{\"sc\":\"hemacash://hmpay\",\"s\":\"Android\",\"id\":\"cn.zishantang.mall\",\"n\":\"杉德支付\"},{\"sc\":\"hemacash://hmpay\",\"s\":\"IOS\",\"id\":\"cn.zishantang.mall\",\"n\":\"\"}]"
					};


					this.$u.post('/api/Redpacket/appsdk', {
						orderjson: JSON.stringify(orderjson)
					}).then(res => {
                        console.log(res)
						console.log(res.data)
						// console.log(res.data.cashier_url)
						let url =res.data.cashier_url;
						// let url = 'https://cash.sandgate.cn/h5/?' + res
						// 	.data.url +
						// 	'#/pczm';
						console.log(url)
						// return;
						// #ifdef H5
						window.location.href = url
						// #endif
						
						// #ifdef APP-PLUS
						plus.runtime.openURL(url);
						// #endif
						
						
					});

				});


			}
		},
	};
</script>

<style lang="scss" scoped>
	.buy {
		width: 100%;
		height: 100%;

		.title {
			display: flex;
			align-items: center;
			padding: 42rpx 0 20rpx 50rpx;
			background-color: #ffffff;

			>image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 6rpx;
			}

			>text {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
				line-height: 40rpx;
			}

			.num {
				color: #ff4141;
			}
		}

		.number {
			width: 100%;
			height: 640rpx;
			background-color: #ffffff;
			margin-top: 18rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			.list {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-between;
				padding: 38rpx 40rpx 66rpx 40rpx;

				.item {
					width: 154rpx;
					height: 194rpx;
					background: #ffffff;
					box-shadow: 0rpx 0rpx 6rpx 0rpx rgba(0, 0, 0, 0.1);
					border-radius: 20rpx;
					margin-bottom: 44rpx;
					display: flex;

					.card {
						width: 154rpx;
						height: 194rpx;
						display: flex;
						flex-direction: column;
						align-items: center;
						justify-content: center;

						.top {
							display: flex;
							align-items: center;

							>text {
								font-size: 32rpx;
								font-family: PingFangSC-Semibold, PingFang SC;
								font-weight: 600;
								color: #666666;
								line-height: 44rpx;
								margin-right: 12rpx;
							}

							>image {
								width: 30rpx;
								height: 30rpx;
							}
						}

						.money {
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;
							line-height: 34rpx;
							margin-top: 12rpx;
						}
					}

					.recommend {
						width: 112rpx;
						height: 36rpx;
						background: #f3f2ea;
						border-radius: 8rpx 0rpx 8rpx 0rpx;
						position: absolute;
						text-align: center;
						margin-top: -18rpx;

						>text {
							font-size: 20rpx;
							font-family: PingFangSC-Medium, PingFang SC;
							font-weight: 500;
							color: #666666;
							line-height: 36rpx;
						}
					}
				}

				.real {
					border: 2rpx solid #f88700;
				}

				&:after {
					content: '';
					width: 194rpx;
				}
			}

			.sure {
				width: 582rpx;
				height: 80rpx;
				background: #ff6a5f;
				border-radius: 40rpx;
				text-align: center;

				>text {
					font-size: 28rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 600;
					color: #ffffff;
					line-height: 80rpx;
				}
			}
		}

		.tip {
			height: 394rpx;
			background: #ffffff;
			margin-top: 18rpx;
			padding: 40rpx;

			.titl {
				font-size: 28rpx;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 600;
				color: #666666;
				line-height: 40rpx;
				margin-bottom: 6rpx;
			}

			>view {
				>text {
					font-size: 22rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					color: #999999;
					line-height: 32rpx;
				}

				&:nth-child(2) {
					>text:nth-child(2) {
						color: #333333;
					}
				}

				&:nth-child(5) {
					>text:nth-child(2) {
						color: #ff6a5f;
						font-weight: 600;
						border-bottom: 2rpx solid #ff6a5f;
					}
				}
			}
		}
	}
	.detail-btn {
	  margin-left: auto;
	  margin-right: 30rpx;
	  font-size: 24rpx;
	  color: #ff6a5f;
	  padding: 6rpx 14rpx;
	  border: 1rpx solid #ff6a5f;
	  border-radius: 20rpx;
	}
</style>